gusucode.com > VC++ CStatic文字滚动特效-源码程序 > VC++ CStatic文字滚动特效-源码程序/code/CStatic文字滚动a/CCreditsCtrl_demo/CreditsDlgDlg.cpp

    // CreditsDlgDlg.cpp : implementation file
// Download by http://www.NewXing.com

#include "stdafx.h"
#include "CreditsDlg.h"
#include "CreditsDlgDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCreditsDlgDlg dialog

CCreditsDlgDlg::CCreditsDlgDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCreditsDlgDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCreditsDlgDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CCreditsDlgDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCreditsDlgDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCreditsDlgDlg, CDialog)
	//{{AFX_MSG_MAP(CCreditsDlgDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BACKGROUND, OnBackground)
	ON_BN_CLICKED(IDC_SLOW, OnSlow)
	ON_BN_CLICKED(IDC_USERSCROLL, OnUserscroll)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCreditsDlgDlg message handlers

BOOL CCreditsDlgDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	srand((unsigned)time(NULL));
	
	// initialize credits control...

	// Content
	CString s;
	s = "<font color='255,255,255' face='arial' size='12' align='center'>";
	s += "<font size='28' face='Comic Sans MS' style='ui' color='255,255,255'>Demo Stuff </font><p>";
	s += "  <font style='bu' align='left'>Color:<br></font><font color='255,0,0'>y</font><font color='220,30,10'>e</font><font color='200,60,30'>e</font><font color='200,100,50'>e</font><font color='180,120,80'>e</font><font color='160,140,100'>e</font><font color='140,160,120'>e</font><font color='120,180,140'>e</font><font color='100,200,160'>e</font><font color='80,180,180'>e</font><font color='60,140,220'>e</font><font color='80,120,250'>h</font><font color='110,100,255'>a</font><font color='130,90,255'>a</font><font color='150,80,255'>a</font><font color='170,70,255'>a</font><font color='180,50,255'>a</font><br>";
	s += "  <font style='bu' align='left'>Font:<br></font><font color='0,200,100' size='14' face='Comic Sans MS'>Comic Sans MS</font><br><font color='0,200,100' size='14' face='Courier New'>Courier New</font><br><font color='0,200,100' size='14' face='Tahoma'>Tahoma</font><br>";
	s += "  <font style='bu' align='left'>Size:<br></font><font color='150,100,255'><font size='42'>W</font><font size='36'>H</font><font size='28'>O</font><font size='18'>O</font><font size='14'>O</font><font size='18'>O</font><font size='28'>O</font><font size='36'>O</font><font size='42'>W</font></font><br>";
	s += "  <font style='bu' align='left'>Styles:<br></font><font color='40,120,240' size='14'><font style='b'>bold</font>  <font style='i'>italic</font>  <font style='u'>underline</font>  <font style='s'>strikeout</font></font><br>";
	s += "  <font style='bu' align='left'>Background:<br></font><font color='255,255,255' size='14' style='b'><font background='0,0,255'>Blue</font>  <font background='255,0,0'>Red</font>  <font background='210,150,40'>Brown</font>  <font background='0,0,255' color='none'>Ghost Font</font></font><br>";
	s += "  <font style='bu' align='left'>Alignment:<br></font><font color='255,150,40' size='14' style='b'><font align='right'>right <br></font><font align='center'>center<br></font><font align='left'> left<br></font></font>";
	s += "  <font style='bu' align='left'>Vertical Alignment:<br></font><font color='0,220,160' size='12' style='b'><font valign='top'>top</font><font valign='middle'>middle</font><font valign='bottom'>bottom</font><font size='48'>BIG</font></font><br>";
	s += "  <font style='bu' align='left'>Resource Bitmap:<br></font><font color='30,70,255' size='12' style='b'><img src='#%d'><font color='255,0,0'>    red </font><font valign='bottom'>bo</font><font valign='middle'>rd</font><font valign='top'>er </font><img src='#%d' border='4' color='255,0,0'></font><br>";
	s += "  <font style='bu' align='left'>Links:<br></font><font color='100,160,220' size='14' style='b'><a href='#Hello World!#%d' color='100,220,160'>Click Me!</a><br><a href='notepad.exe' color='100,220,160' style='bui'>notepad</a><br><a href='http://www.w3c.org' color='100,220,160' face='Courier New' size='16'>www.w3c.org</a><br><a href='mailto:devix@devix.cjb.net?SUBJECT=Hello World!! ;)' color='100,220,160' face='Comic Sans MS' size='18'>devix@devix.cjb.net</a><br><font size='36' color='255,200,0' style='u'><a href='#\nDo or do not. There is no try.\n\n\t\t-Yoda#%d' color='none' background='255,200,0' style='-uis'>Click Here</a></font><vspace size='4'><font valign='top' size='12' style='-b'>image link:  </font><a href='#%d#%d' color='255,200,0'><img src='#%d' border='2' color='none'></a></font><vspace size='80'>";
	s += "<font size='28' face='Comic Sans MS' style='ui'>CCreditsCtrl </font><p><font size='18' style='u' color='255,200,0'>About</font><p>Coded in January 2001<br>by <font style='b'>Marc Richarme</font><vspace size='5'><font align='left' size='11'><hspace size='30'><font style='i'>mail:   </font><font style='ub'><a href='mailto:devix@devix.cjb.net?SUBJECT=Hello World!' color='255,200,0'>devix@devix.cjb.net</a></font><br><hspace size='30'><font style='i'>web:   </font><font style='ub'><a href='http://devix.cjb.net' color='255,200,0'>http://devix.cjb.net</a></font><p></font><font size='18' style='u' color='255,200,0'>Credits</font><p>Thanks to <font style='ub'><a href='http://www.codeproject.com' color='255,200,0'>The Code Project</a></font> for being<br> the coolest VC++/MFC site out there!<br></font><vspace size='80'>";

	// Content Data
	m_wndCredits.FormatDataString(s,IDB_BITMAP1,IDB_BITMAP1,(long)CCreditsDlgDlg::TestFunction,(long)CCreditsDlgDlg::TestFunction,(long)this,(long)CCreditsDlgDlg::TestFunction2,IDB_BITMAP2);
	
	// use our own function for background drawing
	m_wndCredits.m_pBackgroundPaint = CCreditsDlgDlg::DrawCreditsBackground;
	m_wndCredits.m_dwBackgroundPaintLParam = TRUE;

	// as our background is going to be black, use black as default transparent color
	m_wndCredits.m_crInternalTransparentColor = RGB(0,0,0);
	
	// now, we're ready to begin... create the window
	m_wndCredits.Create(WS_EX_CLIENTEDGE,WS_VISIBLE|WS_CHILD,IDC_PLACEHOLDER,this,0,IDC_SMILEY,0);

	// for details on what more can be customized, RTFM.


	// default options
	((CButton*)GetDlgItem(IDC_BACKGROUND))->SetCheck(TRUE);
	((CButton*)GetDlgItem(IDC_USERSCROLL))->SetCheck(TRUE);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CCreditsDlgDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CCreditsDlgDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

// this is our custom background drawing function...
//   it's probably not the most beatifull background effect, but it does
//   demonstrate how custom background drawing should/could be done.. enjoy
void CCreditsDlgDlg::DrawCreditsBackground(CDC *pDC, RECT rect, BOOL bAnimate, DWORD lParam)
{
	static int on1,on2,oon1,oon2;
	pDC->FillSolidRect(&rect,0x00000000);
	
	// uncomment the following lines if you like small green squares :)

//	pDC->SetBkColor(0x000000);
//	CBrush bgBrush;
//	bgBrush.CreateHatchBrush(HS_CROSS,RGB(0,70,30));
//	pDC->FillRect(&rect,&bgBrush);
	
	if(bAnimate || (!lParam)) // return now if we are not supposed to do the animation
		return;

	int n1,n2;
	n1 = rand()*200/RAND_MAX-100;
	n2 = rand()*200/RAND_MAX-100;

	// 2/10 chance of (prehaps) making some wild stuff on one of the curves
	if(rand() < RAND_MAX/10)
		n1 = rand()*400/RAND_MAX-200;
	else if(rand() < RAND_MAX/10)
		n2 = rand()*400/RAND_MAX-200;

	POINT points1[4] = {
		rect.right,0,
		(rect.right-rect.left)/2+n1,(rect.bottom-rect.top)/2,
		(rect.right-rect.left)/2,(rect.bottom-rect.top)/2-n1,
		0,rect.bottom
	};
	POINT points2[4] = {
		0,0,
		(rect.right-rect.left)/2-n2,(rect.bottom-rect.top)/2,
		(rect.right-rect.left)/2,(rect.bottom-rect.top)/2-n2,
		rect.right,rect.bottom
	};
	POINT opoints1[4] = {
		rect.right,0,
		(rect.right-rect.left)/2+on1,(rect.bottom-rect.top)/2,
		(rect.right-rect.left)/2,(rect.bottom-rect.top)/2-on1,
		0,rect.bottom
	};
	POINT opoints2[4] = {
		0,0,
		(rect.right-rect.left)/2-on2,(rect.bottom-rect.top)/2,
		(rect.right-rect.left)/2,(rect.bottom-rect.top)/2-on2,
		rect.right,rect.bottom
	};
	POINT oopoints1[4] = {
		rect.right,0,
		(rect.right-rect.left)/2+oon1,(rect.bottom-rect.top)/2,
		(rect.right-rect.left)/2,(rect.bottom-rect.top)/2-oon1,
		0,rect.bottom
	};
	POINT oopoints2[4] = {
		0,0,
		(rect.right-rect.left)/2-oon2,(rect.bottom-rect.top)/2,
		(rect.right-rect.left)/2,(rect.bottom-rect.top)/2-oon2,
		rect.right,rect.bottom
	};

	CPen wpen(PS_SOLID,1,RGB(150,220,255));
	CPen pen(PS_SOLID,2,RGB(50,100,255));
	CPen open(PS_SOLID,1,RGB(50,100,255));
	CPen oopen(PS_SOLID,1,RGB(0,30,150));
	CPen *pOldPen = pDC->SelectObject(&oopen);
	pDC->PolyBezier(oopoints1,4);
	pDC->PolyBezier(oopoints2,4);
	pDC->SelectObject(&open);
	pDC->PolyBezier(opoints1,4);
	pDC->PolyBezier(opoints2,4);
	pDC->SelectObject(&pen);
	pDC->PolyBezier(points1,4);
	pDC->PolyBezier(points2,4);
	pDC->SelectObject(&wpen);
	pDC->PolyBezier(points1,4);
	pDC->PolyBezier(points2,4);
	pDC->SelectObject(pOldPen);

	oon1 = on1;
	oon2 = on2;
	on1 = n1;
	on2 = n2;
}

void CCreditsDlgDlg::TestFunction(LPCTSTR lpszArg)
{
	if(lpszArg == NULL)
		AfxMessageBox("(null)");
	else
		AfxMessageBox(lpszArg);
}

void CCreditsDlgDlg::TestFunction2(LPCTSTR lpszArg)
{
	static int cnt = 1;
	CCreditsDlgDlg *pDlg = (CCreditsDlgDlg*)atol(lpszArg);
	
	pDlg->m_wndCredits.m_nTimerSpeed = cnt==0 ? 30 : cnt * 40;
	
	if(++cnt > 3)
		cnt = 0;
}

void CCreditsDlgDlg::OnBackground() 
{
	m_wndCredits.m_dwBackgroundPaintLParam = (DWORD)((CButton*)GetDlgItem(IDC_BACKGROUND))->GetCheck();
}

void CCreditsDlgDlg::OnSlow() 
{
	m_wndCredits.m_nTimerSpeed = ((CButton*)GetDlgItem(IDC_SLOW))->GetCheck() ? 80 : 40;
}

void CCreditsDlgDlg::OnUserscroll() 
{
	m_wndCredits.m_bCanScroll = ((CButton*)GetDlgItem(IDC_USERSCROLL))->GetCheck();
}